<template>
  <div class="masx-1">
    <van-pull-refresh v-model="refreshing" @refresh="onRefresh">
      <van-list
        v-model:loading="loading"
        :finished="finished"
        finished-text="没有更多了"
        @load="onLoad"
      >
        <Carll v-for="(item, index) in list" :key="index" :item />
      </van-list>
    </van-pull-refresh>
  </div>
</template>

<script lang="ts" setup>
import Carll from './Carll.vue'
import { ref } from 'vue'
import { getFeedback } from '@/services/user'
const list: any = ref([])
const loading = ref(false)
const finished = ref(false)
const refreshing = ref(false)
const obj: any = ref({
  pageNum: 1,
  pageSize: 10
})
const onLoad = async () => {
  try {
    const res = await getFeedback(obj.value)
    list.value.push(...res.data)
    //total这个是总条数
    if (obj.value.pageNum >= Math.ceil(res.data.length / obj.value.pageSize)) {
      finished.value = true
    } else {
      obj.value.pageNum++
    }
  } catch (error) {
    console.error('加载数据失败:', error)
  } finally {
    loading.value = false
    refreshing.value = false
  }
}

const onRefresh = () => {
  // 清空列表数据
  finished.value = false
  obj.value.pageNum = 1
  list.value = []
  // 重新加载数据
  // 将 loading 设置为 true，表示处于加载状态
  loading.value = true
  onLoad()
}
</script>

<style lang="scss" scoped>
.masx-1 {
  width: 100%;
  height: 100%;
  background: #f1f1f1;
  padding: 10px;
  box-sizing: border-box;
}
</style>
